package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class ForEachDemo {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap();
        map.put("语文",98);
        map.put("数学",99);
        map.put("英语",97);
        map.put("物理",95);
        map.put("历史",91);
        System.out.println(map);

        Set<String> keySet = map.keySet();
        keySet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        keySet.forEach(k-> System.out.println(k));

        Collection<Integer> value = map.values();
        value.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer v) {
                System.out.println(v);
            }
        });
        value.forEach(v-> System.out.println(v));

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        entrySet.forEach(new Consumer<Map.Entry<String, Integer>>() {
            @Override
            public void accept(Map.Entry<String, Integer> entry) {
                System.out.println(entry);
            }
        });
        entrySet.forEach(e-> System.out.println(e.getKey()+"="+e.getValue()));

        map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String string, Integer integer) {
                System.out.println(string+":"+integer);
            }
        });
        map.forEach((k,v)-> System.out.println(k));
        map.forEach((k,v)-> System.out.println(v));
        map.forEach((k,v)-> System.out.println(k+","+v));
    }
}
